home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / validadd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  2.1 KB  |  63 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_AUX_SEG
  14. #pragma code_seg(AFX_AUX_SEG)
  15. #endif
  16.  
  17.  
  18. // AfxIsValidString() returns TRUE if the passed pointer
  19. // references a string of at least the given length in characters.
  20. // A length of -1 (the default parameter) means that the string
  21. // buffer's minimum length isn't known, and the function will
  22. // return TRUE no matter how long the string is. The memory
  23. // used by the string can be read-only.
  24.  
  25. BOOL AFXAPI AfxIsValidString(LPCWSTR lpsz, int nLength /* = -1 */)
  26. {
  27.     if (lpsz == NULL)
  28.         return FALSE;
  29.     return afxData.bWin95 || ::WCE_FCTN(IsBadStringPtrW)(lpsz, nLength) == 0;
  30. }
  31.  
  32. // As above, but for ANSI strings.
  33.  
  34. BOOL AFXAPI AfxIsValidString(LPCSTR lpsz, int nLength /* = -1 */)
  35. {
  36.     if (lpsz == NULL)
  37.         return FALSE;
  38. #if defined(_WIN32_WCE)
  39. // WinCE: our workaround is to check to see if the first character 
  40. // and last character are readable
  41.     if(IsBadReadPtr(lpsz, 1))
  42.         return FALSE;
  43.     return ::IsBadReadPtr(lpsz + min((UINT)nLength, (UINT)strlen(lpsz)), 1) == 0;
  44. #else // _WIN32_WCE
  45.     return afxData.bWin95 || ::WCE_FCTN(IsBadStringPtrA)(lpsz, nLength) == 0;
  46. #endif // _WIN32_WCE
  47. }
  48.  
  49. // AfxIsValidAddress() returns TRUE if the passed parameter points
  50. // to at least nBytes of accessible memory. If bReadWrite is TRUE,
  51. // the memory must be writeable; if bReadWrite is FALSE, the memory
  52. // may be const.
  53.  
  54. BOOL AFXAPI AfxIsValidAddress(const void* lp, UINT nBytes,
  55.     BOOL bReadWrite /* = TRUE */)
  56. {
  57.     // simple version using Win-32 APIs for pointer validation.
  58.     return (lp != NULL && !IsBadReadPtr(lp, nBytes) &&
  59.         (!bReadWrite || !IsBadWritePtr((LPVOID)lp, nBytes)));
  60. }
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63.